package DataBaseQuery;

import DataBaseManager.Row;
import DataBaseManager.Table;
import DataType.MyDataType;
import java.util.ArrayList;

public class VariableReference {
	String subTableName;
	String tableName;
	public String fieldName;
	public MyDataType value;
	public VariableReference(String field,MyDataType val)
	{
		fieldName = field;
		value = val;
	}
	public VariableReference(String table,String field,MyDataType val)
	{
		tableName = table;
		fieldName = field;
		value = val;
	}
	
	public void setValue(MyDataType val)
	{
		value = val;
	}
	
	public VariableReference(String table,String field)
	{
		tableName = table;
		fieldName = field;
	}
	public static ArrayList<VariableReference> getVaribleRefFromTable(Table table,int currentRow)
	{
		ArrayList<VariableReference> listVarRefs = new ArrayList<VariableReference>();
		Row dataRow = table.getDataRow(currentRow);
		for (int j = 0; j < table.getFields().size(); j++) {
			listVarRefs.add(new VariableReference(table.getName(),
					table.getFieldName(j), dataRow.getValue(j)));
		}
		return listVarRefs;
	}
	public static ArrayList<VariableReference> getVaribleRefFromTable(Table table)
	{
		ArrayList<VariableReference> listVarRefs = new ArrayList<VariableReference>();
		for (int j = 0; j < table.getFields().size(); j++) {
			listVarRefs.add(new VariableReference(table.getName(),table.getFieldName(j)));
		}
		return listVarRefs;
	}
	
	public String getFullName() {
		return tableName+"."+fieldName;
	}

	public boolean is(String name)
	{
		if(subTableName != null && subTableName.length() > 0 && name.equalsIgnoreCase(subTableName+"."+fieldName))
			return true;
		return name.equalsIgnoreCase(getFullName()) || name.equalsIgnoreCase(fieldName);
	}
}
